const service = require('./rankingService.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    isSelect: 2,
    type: 2,
    activeRule:"",
    awardContext:"日奖励",
    time: "20：50",
    rankList:[
    ],

    mine: {
    },
    colors:[
      "#fff7cb", "#fff7cb", "#fff7cb", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff"
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this;
    //授权
    self.authAlert = self.selectComponent("#authAlert");
    self.authAlert.bindCatch()
    getApp().loginPromise.then(() => {
      self.loadData()
    });
  },

  /**
   * 点击授权
   */
  authSuccess() {
    this.loadData()
  },

  loadData:function(){
    var self = this;
    service.getRanking(this.data.type, function (res) {
      if (res.awardContext != "") {
        self.setData({
          awardContext: res.awardContext,
        })
      }
      if (res.time != "") {
        self.setData({
          time: res.time,
        })
      }
      self.setData({
        rankList: res.userRankIngVos,
        mine: res.userRankIngVo,
        activeRule: res.activeRule
      })
    });
  },

  selectDay: function () {
    var self = this;
    if (this.data.isSelect == 2) {
      return
    }
    this.setData({
      isSelect: 2,
      type: 2,
      scrollTop: 0
    })
    service.getRanking(2, function (res) {
      if (res.awardContext != "") {
        self.setData({
          awardContext: res.awardContext,
        })
      }
      if (res.time != "") {
        self.setData({
          time: res.time,
        })
      }
      self.setData({
        rankList: res.userRankIngVos,
        mine: res.userRankIngVo,
        activeRule: res.activeRule
      })
    });
  },
  goRule: function(e){
    wx.navigateTo({
      url: './rankingRule/rankingRule?type=111',
    })
  },
  selectWeek: function(){
    var self = this;
    if (this.data.isSelect == 0){
      return
    }
    this.setData({
      isSelect: 0,
      type: 0,
      scrollTop: 0
    })
    service.getRanking(0, function (res) {
      if (res.awardContext != "") {
        self.setData({
          awardContext: res.awardContext,
        })
      }
      if (res.time != "") {
        self.setData({
          time: res.time,
        })
      }
      self.setData({
        rankList: res.userRankIngVos,
        mine: res.userRankIngVo,
        activeRule: res.activeRule
      })
    });
  },  
  selectMonth: function (){
    var self = this;
    if (this.data.isSelect == 1) {
      return
    }
    this.setData({
      isSelect: 1,
      type: 1,
      scrollTop: 0
    })
    service.getRanking(1, function (res) {
      if (res.awardContext != "") {
        self.setData({
          awardContext: res.awardContext,
        })
      }
      if (res.time != "") {
        self.setData({
          time: res.time,
        })
      }
      self.setData({
        rankList: res.userRankIngVos,
        mine: res.userRankIngVo,
        activeRule: res.activeRule
      })
    });
  },

})